<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/1/3-16:21
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->

{extend name='public/base' /}


{block name="content"}

<!--左侧开始-->
<div class="layui-col-md2 ">
    <div class="layui-card">
        <div class="layui-card-header">
            角色列表
        </div>
        <div class="layui-card-body layui-row ">
            <div class="demo-tree-more" id="menuLfetTree">
            </div>

        </div>

    </div>

</div>
<!--左侧结束-->

<div class="layui-col-md10">

    <div class="layui-card">
        <div class="layui-card-body layui-row ">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">

                    <div class="layui-inline">
                        <label class="layui-form-label">管理员搜索：</label>
                        <div class="layui-input-inline">
                            <input name="name" class="layui-input" value="" type="text" placeholder="请输入名称">
                        </div>
                    </div>

                    <div class="layui-inline" style="padding-left: 20px;">
                        <button class="layui-btn icon-btn layui-btn-sm" lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" onclick="javascript:window.location.reload();">
                            <i class="layui-icon layui-icon-refresh"></i> 重置
                        </button>
                    </div>

                </div>

            </form>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-card-header" style="line-height: 55px;">
            <div class="layui-btn-container do_btn">
                <!--按钮区-->
                <button class="layui-btn layui-btn-sm" data-type="add_menu"><i class="layui-icon"></i>新增管理员</button>
                <button class="layui-btn layui-btn-sm layui-btn-danger" data-type="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="reload"><i class="fa fa-refresh"></i> 刷新</button>
            </div>
        </div>
        <div class="layui-card-body">

            <!--表格区-->

            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>


{/block}


{block name="js"} <!--js处理区-->


<!--模板-->
<script type="text/html" id="operationTpl">
    {{# if(d.id!=1){ }}

    {:widget('common/forms/Editbtn',array('编辑管理员信息'))}

    {:widget('common/forms/Delbtn',array('删除管理员',2))}

    {{# }else{ }}
         不可编辑
    {{# } }}
</script>

<script type="text/html" id="status">
    <input type="checkbox" name="status"  lay-data="{{d.status}}" value="{{d.id}}"  lay-filter="sexDemo" lay-skin="switch"  lay-text="正常|拉黑"  {{ d.status == 1 ? 'checked' : '' }}>
</script>


<script>

    layui.use(['element', 'table', 'form', 'jquery', 'lucky','tree'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var tree=layui.tree;
        form.render();

        $.ajax({
            url:"{:url('tree')}",
            type:'post',
            async: true,
            dataType: "json",
            data:{},
            error: function(error) {
                layer.msg("服务器错误或超时");
                return false;
            },
            success:function(res)
            {
                //基本演示
                tree.render({
                    elem: '#menuLfetTree'
                    ,data: res.data
                    ,showCheckbox: false  //是否显示复选框
                    ,id: 'demoId1'
                    ,isJump: false //是否允许点击节点时弹出新窗口跳转
                    ,click: function(obj){
                        var data = obj.data;  //获取当前点击的节点数据
                          layui.table.reload("table_id", {
                              page: {
                                  curr: 1 //重新从第 1 页开始
                              },where:{role_id:data.id}
                          }, 'data');
                    }
                });
            }
        });

        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('admin/index')}",
            //toolbar: '#toolbarDemo',
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[10,20,30,50]
            },
            //height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                {field:'avatar',title:"头像", width:80,templet:function (d) {
                        return '<img  src="'+d.avatar+'" class="layui-nav-img" alt="无图" />';
                    }},
                {field: 'nickname', minWidth: 150, title: '管理员昵称'},
                {field: 'name', width: 150, title: '所属角色'},
                {field: 'username', width: 110, title: '用户名'},
                {field: 'pass', width: 110, title: '密码'},
                {field: 'sex', width: 70, title: '性别'},
                {field:'status',title:'状态',templet: '#status',width:110 ,unresize: true,sort:true},
                {field: 'create_time', title: '添加时间',align: 'center',width:150,sort:true},
                {fixed: 'right',templet: '#operationTpl', width: 150, align: 'center', title: '操作'}
            ]],

            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch("table_id",obj.field); //查询
            return false;
        });



        /**
         * 监听是否显示操作
         */
        form.on('switch(sexDemo)', function(obj){
            var _id=parseInt(obj.value);
            var pan=obj.elem.checked;
            var status;
            if (pan===false){
                status=2;
            }else {
                status=1;
            }
            lucky.Change_status("{:url('common/changeStatus')}","table_id","admin_user",_id,"status",status, obj.othis);
        });



        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="edit"){
                var urls="{:url('editUser')}?id="+_id;
                lucky.CreateForm("编辑管理员信息",'55%','70%',urls,"table_id");

            }else if(layEvent==="del"){
                lucky.Delete_data(_id,"{:url('del')}","table_id");
            }
        });


        var active = {
            add_menu:function(){
                lucky.CreateForm("添加管理员",'55%','70%',"{:url('addUser')}","table_id");
            },
            del: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.Delete_data(id,"{:url('del')}","table_id");
            },
            reload: function(){
                lucky.CreateReload("table_id");
            },
            move:function () {
                layer.msg("功能待开发",{time:1500});return false;
            }
        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


{/block}
